<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>修改密码</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui2/aui.css" />
	<style>
        body, html {
            height: 100%;
        }
        .button.green {
            background-color: #009688;
        }
        .button.green:active{
            background-color: #0068B0;
        }
        .button {
            display: block;
            color: white;
            margin: 0px 0px;
            text-align: center;
            border-radius: 3px;
            height: 40px;
            line-height: 40px;
        }
        .login-error {
            color: #FF0000;
            font-size: 18px;
            text-indent: 2em;
            display: none;
            padding-top: 8px;
        }
        .hint{
            margin-top:20px;
        }
        .hint span{
            text-align:center;
            display:block;
        }
        .content{
            position:absolute;
            width:100%;
            top:20%;
        }
        input[type="password"],input[type="text"]{
            margin-bottom:0;
        }
        .red{
        	border:1px solid red !important;
        }
        .hidden{
        	display:none;
        }
	</style>
</head>
<body>
	<header class="aui-bar aui-bar-nav">
        <div class="aui-pull-left aui-btn" id="btn_return" onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>返回
        </div>
        <div class="aui-title">修改密码</div>
    </header>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-list-in ">
        	<li class="aui-list-header"></li>
    		<li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        	旧密码
                    </div>
                    <div class="aui-list-item-input">
                        <input id="password_old" type="password" maxlength="20" class="txt" placeholder="旧密码">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        	新密码
                    </div>
                    <div class="aui-list-item-input">
                        <input id="password_new" type="password" maxlength="20" class="txt" placeholder="新密码">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        	确认密码
                    </div>
                    <div class="aui-list-item-input">
                        <input id="password_new2" type="password" maxlength="20" class="txt" placeholder="确认密码">
                    </div>
                </div>
            </li>
           <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner aui-list-item-center aui-list-item-btn">
                    <div class="aui-btn aui-btn-info aui-margin-r-5" onclick="changePwd()">提交</div>
                </div>
            </li>-->
         </ul>
    </div>
    <div class="button green" tapmode="" onclick="changePwd()">
       	 确认修改
    </div>
</body>
<script data-main="../../script/main" src="../../script/require.js"></script>
<script type="text/javascript">
	apiready = function(){
		require(["zepto","api","md5","common"],function(){
			var header = $api.dom('header');
			$api.fixStatusBar(header);
			
			$(".txt").on("focus",function(){
	        	$(this).removeClass("red");	
	    	});
		})
	};
	function changePwd(){
		var retmsg = check();
		if(retmsg){
    		api.toast({
                msg:retmsg
            });
    		return;
    	}
		$zb.prefs.getPrefs('token',function(result) {
	        if(result.value) {
				$zb.requestForData({values:{token:result.value,password_old:$zb.getmd5text($('#password_old').val()),password_new:$zb.getmd5text($('#password_new').val())}}, 'user','changePassword', function(ret) {
		            if (ret.status == 'OK') {
		            	api.toast({ msg: '修改成功' });
						api.closeWin();
		            }else {
		                api.toast({ msg: ret.status });
		            }
		        });
	        }
	    });
	}
	function check(){
		var ret_message=null;
    	if(!$("#password_old").val()){
    		ret_message = "请输入旧密码";
    		$("#password_old").addClass("red");
    		return ret_message;
    	}
    	if(!$("#password_new").val()){
    		ret_message = "请输入新密码";
    		$("#password_new").addClass("red");
    		return ret_message;
    	}
    	if($("#password_new").val()!=$("#password_new2").val()){
    		ret_message = "确认密码不一致";
    		$("#password_new2").addClass("red");
    		return ret_message;
    	}
	}
</script>
</html>